package common.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;


/**
 * @Author: 郑国荣
 * @Date: 2024-03-26-16:32
 * @Description:
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = SQLException.class)
    @ResponseBody
    public String handleSQLIntegrityConstraintViolation(SQLException e) {
        System.out.println("数据库完整性约束违反：" + e.getMessage());
        return "数据库完整性约束违反：" + e.getMessage();
    }
}
